//
//  FNBannerCollectionViewCellFactory.swift
//  FNBanner
//
//  Created by Fnoz on 2016/10/25.
//  Copyright © 2016年 Fnoz. All rights reserved.
//

import UIKit

class FNBannerCollectionViewCellFactory: NSObject {
    
    class func cell(collectionView: UICollectionView, indexPath: IndexPath, style: BannerStyle, imageUrl: String? = nil, placeHolder:UIImage? = nil) -> FNBannerCollectionViewBaseCell {
        var cell: FNBannerCollectionViewBaseCell?
        switch style {
        case .style0:
            cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(FNBannerCollectionViewCell0.self), for: indexPath as IndexPath) as! FNBannerCollectionViewCell0
        case .style1:
            cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(FNBannerCollectionViewCell1.self), for: indexPath as IndexPath) as! FNBannerCollectionViewCell1
        case .style2:
            cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(FNBannerCollectionViewCell2.self), for: indexPath as IndexPath) as! FNBannerCollectionViewCell2
            break
        }
        cell?.loadImageUrl(imageUrl: imageUrl, placeHolder: placeHolder)
        return cell!
    }
    
    class func cellSize(style: BannerStyle, bannerSize:CGSize) -> CGSize {
        var cellSize = bannerSize
        switch style {
        case .style0:
            cellSize = CGSize.init(width: bannerSize.width, height: bannerSize.height)
        case .style1:
            cellSize = CGSize.init(width: bannerSize.width * 0.3, height: bannerSize.height)
        case .style2:
            cellSize = CGSize.init(width: bannerSize.width * 0.6, height: bannerSize.height)
            break
        }
        return cellSize
    }

}
